#include <vector>
using std::vector;

class Solution
{
public:
    int getLeft(vector<int> &nums, int target, bool isLeft)
    {
        int left = 0;
        int right = nums.size();
        int result = -1;
        while (left < right)
        {
            int temp = left + (right - left) / 2;
            if (nums[temp] == target && isLeft)
            {
                right = temp;
                result = temp;
            }
            else if (nums[temp] < target)
            {
                left = temp + 1;
            }
            else if (nums[temp] > target)
            {
                right = temp;
            }
            else if (nums[temp] == target && !isLeft)
            {
                left = temp + 1;
                result = temp;
            }
        }
        return result;
    }

    vector<int> searchRange(vector<int> &nums, int target)
    {
        int leftIndex = getLeft(nums, target, true);
        int rightIndex = getLeft(nums, target, false) - 1;
        if (leftIndex <= rightIndex && rightIndex < nums.size() && nums[leftIndex] == target && nums[rightIndex] == target)
        {
            return vector<int>{leftIndex, rightIndex};
        }
        else
        {
            return vector<int>{-1, -1};
        }
    }
};